package com.ics.atable.chat.controller;

import com.ics.atable.chat.common.BaseResponse;
import com.ics.atable.chat.expection.ErrorCode;
import com.ics.atable.chat.expection.ThrowUtils;
import com.ics.atable.chat.model.dto.EmbeddingRequestDTO;
import com.ics.atable.chat.service.EmbeddingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.ics.atable.chat.common.ResultUtils.success;

/**
 * embedding Controller
 *
 * @author haohongbin
 */
@Tag(name = "Embedding API接口", description = "embedding 接口")
@RestController
@RequestMapping("/embedding")
public class EmbeddingController {

    private final EmbeddingService embeddingService;

    public EmbeddingController(EmbeddingService embeddingService) {
        this.embeddingService = embeddingService;
    }

    @Operation(summary = "调用embedding接口")
    @PostMapping("/call")
    public BaseResponse<EmbeddingResponse> embedding(@RequestBody EmbeddingRequestDTO request) {
        ThrowUtils.throwIf(CollectionUtils.isEmpty(request.getTextList()), ErrorCode.PARAMS_ERROR, "文本列表不能为空");

        EmbeddingResponse embeddingResponse = embeddingService.embedding(request.getTextList());
        return success(embeddingResponse);
    }
}
